package com.hk.controller;

import com.hk.Enume.OperationType;
import com.hk.annotation.AotoFile;
import com.hk.constant.LogConstaant;
import com.hk.core.Result;
import com.hk.core.basePageResult.BasePageResult;
import com.hk.domain.Course;
import com.hk.dto.CourseDto;
import com.hk.mapper.CourseMapper;
import com.hk.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程信息
 */
@RestController
@Slf4j
@RequestMapping("/clues/course")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private CourseMapper courseMapper;

    /**
     * 根据条件查询课程信息
     * @param courseDto
     * @return
     */
    @GetMapping("/list")
    public BasePageResult getList(CourseDto courseDto){
        BasePageResult basePageResult = courseService.getList(courseDto);
        return basePageResult;
    }

    /**
     * 根据id查询课程信息(修改页面回显)
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getByCourseId(@PathVariable Integer id){
        Course course = courseService.getById(id);
        return Result.success(course);
    }

    /**
     * 修改课程信息
     * @param course
     * @return
     */
    @AotoFile(value = OperationType.PUT,title = LogConstaant.COURSE_LOG)
    @PutMapping
    public Result updateCourse(@RequestBody Course course){
        courseService.updateById(course);
        return Result.success();
    }

    /**
     * 添加课程信息
     * @param course
     * @return
     */
    @AotoFile(value = OperationType.POST,title = LogConstaant.COURSE_LOG)
    @PostMapping
    public Result addCourse(@RequestBody Course course){
        courseService.addCourse(course);
        return Result.success();
    }

    /**
     * 删除课程信息
     * @param id
     * @return
     */
    @AotoFile(value = OperationType.DELETE,title = LogConstaant.COURSE_LOG)
    @DeleteMapping("/{id}")
    public Result deleteCourse(@PathVariable Integer id){
        courseService.removeById(id);
        return Result.success();
    }

    /**
     * 获取课程下拉列表
     * @return
     */
    @GetMapping("/listselect")
    public Result listSelect(){
        List<Course> courses = courseMapper.selectList(null);
        return Result.success(courses);
    }
}
